public class FindNumsAppearOnce {
    // 只出现一次的数字
    // https://www.nowcoder.com/practice/389fc1c3d3be4479a154f63f495abff8?tpId=295&tqId=1375231&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3DSQL%25E7%25AF%2587%26topicId%3D295
    public int[] FindNumsAppearOnce (int[] nums) {
        // write code here
        int num1 = 0, num2 = 0;
        int num = 0;
        for (int n : nums) {
            num ^= n;
        }
        int i = 0;
        while (true) {
            if ((num >> i & 1) == 1) {
                break;
            }
            i++;
        }
        for (int n : nums) {
            if (((n >> i) ^ 1) != 0) {
                num1 ^= n;
            } else {
                num2 ^= n;
            }
        }
        int[] ret = new int[2];
        if (num1 < num2) {
            ret[0] = num1;
            ret[1] = num2;
        } else {
            ret[0] = num2;
            ret[1] = num1;
        }
        return ret;
    }

    public static void main(String[] args) {
        FindNumsAppearOnce obj = new FindNumsAppearOnce();
        int[] nums = {3,6};
        System.out.println(obj.FindNumsAppearOnce(nums));
    }
}
